<template>
  <div class="chart-box" ref="Charts"></div>
</template>

<script>
import resize from '@/components/mixins/resize'

export default {
  title: '堆叠式圆环图',
  name: "EchartBar",
  mixins: [resize],
  props: {
    data: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      chart: null,
    }
  },
  watch: {
    data: {
      deep: true,
      handler: function (val) {
        this.setOptions(val)
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(this.$refs.Charts)
      this.setOptions(this.data)
    },
    setOptions({axis = [], data = [], max}) {
      if (!this.chart) {
        return false
      }
      this.chart.setOption({
        polar: {
          radius: [30, '80%']
        },
        angleAxis: [
          {
            max: max,
            startAngle: 75,
            axisLine: {
              show: false,
              lineStyle: {
                color: '#ffffff',
                width: 1
              }
            },
            axisTick: {
              show: false
            },
            splitLine: {
              show: false
            },
            axisLabel: {
              show: false
            }
          }
        ],
        legend: {
          show: true,
          textStyle:{
            color:'#ffffff'
          },
          data: axis
        },
        radiusAxis: {
          type: 'category',
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          splitLine: {
            show: false
          },
          axisLabel: {
            show: false
          }
          // data: axis
        },
        tooltip: {},
        series: data
      })
    }
  }
}
</script>

<style scoped lang="less">
  .chart-box {
    width: 100%;
    height: 100%;
  }
</style>